<?php
/**
 * Notes:
 * User: Administrator
 * Date: 2020/3/8
 * Time: 12:35
 * ${PARAM_DOC}
 * @return ${TYPE_HINT}
 * ${THROWS_DOC}
 */

namespace app\api\controller;


use app\common\controller\Api;
use app\api\model\User as UserModel;
use think\Db;
use think\Log;

class Notes extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 添加我的项目信息
     * @throws \Exception
     */
    public function add()
    {
        $userId = UserModel::getCurrUid($this->request->param('user_id', 0));
        if ($userId <= 0) {
            $this->error('请重新登录', [],401);
        }

        $user = UserModel::findInfoByCondition(['id' => $userId]);
        if (!$user) {
            $this->error(__('参数错误'));
        }
        if (!$user['mobile']) {
            $this->error(__('手机号为空'));
        }

        $params = $this->request->param();
        $data = isset($params['options']) && $params['options'] ? $params['options'] : [];
        if (!$data) {
            $this->error(__('参数错误'));
        }
        /*        $data = [
                    ['user_id' => 2, 'company_name' => '我是公司名称1', 'pname' => '我是想买名称1', 'p_content' => '我是想买介绍1', 'p_devote' => '我的贡献1'],
                    ['user_id' => 2, 'company_name' => '我是公司名称', 'pname' => '我是想买名称', 'p_content' => '我是想买介绍', 'p_devote' => '我的贡献'],
                ];*/
        $add = new \app\api\model\Notes();
        $res = $add->saveAll($data);

        //用户类型
        $uType = isset($params['u_type']) ? $params['u_type'] : 0;

        if (!in_array($uType, [1, 2])) {
            $this->error(__('用户类型参数错误'));
        }

        if ($uType == 1) {  //专家注册成功
            UserModel::saveData($userId, ['is_expert_reg' => 1]);
        } elseif ($uType == 2) {    //企业注册成功
            UserModel::saveData($userId, ['is_company_reg' => 1]);
        }

        $this->success('success', $res);
    }

    /**
     * 查找我的公司项目信息
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function show()
    {
        $data = $this->request->param();
        $add = new \app\api\model\Notes();
        $res = $add->where('user_id',$this->auth->id)->select();
        $this->success('success', $res);
    }

}